#include <vector>
#include <iostream>
#include <deque>

using namespace std;

enum EColor {
    C_WHITE,
    C_GRAY,
    C_BLACK
};

class Graph{
public:
    vector< vector<int> > cMatrix;
    
    Graph (vector < vector<int> >& g) {
        cMatrix=g;
    }
    
    void BFS(int idx) {
        piArray.resize(0);
        piArray.resize(cMatrix.size(), -1);
        depthArray.resize(cMatrix.size(), 0);

        vector<EColor> colorArray(cMatrix.size(), C_WHITE);
        deque<int> dq;
        dq.push_back(idx);

        colorArray[idx]=C_GRAY;
        depthArray[idx]=0;

        while(!dq.empty()){
            int idx_n = dq.front();
            dq.pop_front();
            colorArray[idx_n]=C_BLACK;

            for(int i=0; i<cMatrix.size(); ++i){
                if( (colorArray[i]==C_WHITE) && (cMatrix[idx_n][i]==1) ){
                    colorArray[i]=C_GRAY;
                    depthArray[i]=depthArray[idx_n]+1;
                    piArray[i]=idx_n;
                    dq.push_back(i);
                    colorArray[i]=C_BLACK;
                }
            }
        }
    }

    int IsPass(int i, int j) {
        this->BFS(i);
        int curV=j;

        while (curV!=-1 && curV!=i) {
            if(piArray[curV]==-1) return 0;
            curV=piArray[curV];
        }
        return curV==i?1:0;
    }
private:
    vector<double> piArray;
    vector<int> depthArray;
};

int main() {
    if(freopen("in.txt", "r", stdin)==NULL) {
        cout<<"Error: input file can't be opened";
        return 1;
    }
    if(freopen("out.txt", "w", stdout)==NULL) {
        cout<<"Error: output file can't be opened";
        return 1;
    }

    int n;
    cin>>n;

    int edges;
    cin>>edges;

    vector < vector<int> > g;
    g.resize(n);
    for(int i=0; i<n; ++i) g[i].resize(n);
    
    int tmpi, tmpj;
    for(size_t i=0; i<edges; ++i) {
        cin>>tmpi>>tmpj;
        g[tmpi][tmpj]=g[tmpj][tmpi]=1;
    }

    Graph G(g);
    
    for(int i=0; i<n; ++i) {
        for(int j=0; j<n; ++j) {
            if((i<j) && G.IsPass(i,j)) cout<<i<<" "<<j<<endl;
        }
    }

    //system("pause");
    return 0;
}